package public

/* 
 * 用户登陆和退出功能
 * author cameron
 */
 
import (
	"gobackstage/code/controllers"
	"github.com/astaxie/beego"
	."gobackstage/code/models/user"
)

//用户登陆结构体
type LoginController struct{
	//继承公共结构体 BaseController
	controllers.BaseController
}

func (l *LoginController) Get()  {
	l.TplName = "admin/public/login.html"
}

func (l *LoginController) Post()  {

	username := l.GetString("username") 
	password := l.GetString("password")
	// l.Ctx.WriteString(username+"="+password)

	//进行帐户和密码判断
	user,err := Logincheck(username,password)

	if err == nil {
		l.SetSession("username", user.Username)

		l.Redirect("/admin/index",302)
		// l.Data["json"] = map[string]interface{}{"code": user, "message": "贺喜你，登录成功"}
	} else {
		// l.Data["json"] = map[string]interface{}{"code": 0, "message": "登录失败"}
		l.Redirect("/admin/login",302)
	}

	// l.ServeJSON()

}

//用户退出结构体
type SignController struct{
	beego.Controller
}

func (s *SignController) Get()  {
	s.DestroySession()
	// ctx.Redirect(302,"/admin/index")
	s.Redirect("/admin/login",302)
}